import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')),
    systemMenus: [],
    currentRole: '',
    customerMenus:[],
  },
  mutations: {
    login(state, user) {
      state.user = user
      window.localStorage.setItem('user', JSON.stringify(user))
    },
    logout(state) {
      state.user = ''
      window.localStorage.removeItem('user')
      state.systemMenus=[]
    },
    getMenus(state, menus) {
      state.systemMenus = menus
    },
    getCurrentRole(state, role) {
      state.currentRole = role
    },
    getCustomerMenus(state,menus){
      state.customerMenus = menus
    }
  }
})
